package com.easyUploader.entity.vo;

import com.common.util.StringUtil;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import static com.easyUploader.property.LocalFileProperty.DEFAULT_BUCKET;

/**
 * @author 大忽悠
 */
@AllArgsConstructor
@NoArgsConstructor
@Data
@Builder
@Slf4j
public class BucketVo {
    /**
     * 存储桶名称
     */
    private String name;

    /**
     * 存储桶类型: 0-只读,1-读写
     */
    private Integer bucketType;

    /**
     * 访问类型: 0-私有,1-公开
     */
    private Integer accessType;

    public static String getDefaultIfNeeded(String bucket) {
            return StringUtil.isNullOrEmpty(bucket)?DEFAULT_BUCKET:bucket;
    }

    public void safeCheck() {
        if (StringUtil.isNullOrEmpty(name)) {
            throw new IllegalArgumentException("存储桶名称为空");
        }
        this.bucketType = bucketType>0?1:0;
        this.accessType = accessType>0?1:0;
    }
}
